

*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* import data sharepost *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* Consumers
use "data/working/cleaned_consumer",clear
duplicates report household_id 
unique household_id
destring currencies_potential, ignore("NA") replace
save "data/working/data_platform.dta", replace 

* Investors
use "data/working/cleaned_investor",clear
duplicates report household_id 
unique household_id

* Append
append using "data/working/data_platform.dta"

 
*------------------------------------------------------------------------------*
* Format Date * 
*------------------------------------------------------------------------------*
format date %td
rename currency currency_id

gen month 		= month(date)	
gen year 		= year(date)
gen wave 		= 1 if (month==1 | month==2 | month==3)
replace wave 	= 2 if missing(wave)
label define wavelabel 1 "Wave 1" 2 "Wave 2"
label values wave wavelabel


*------------------------------------------------------------------------------*
* Control Variables *
*------------------------------------------------------------------------------*
* tot_choice
bys household_id: egen tot_choice = sum(choice)
bys household_id: gen fo_household = _n==1
sort household_id currency_id
label variable tot_choice "Total Choice"


* heard_of_crypto
replace heard_of_crypto = "speculative motive" 				if strpos(heard_of_crypto, "speculat")
replace heard_of_crypto = "investment and purchases motive" if strpos(heard_of_crypto, "investment") & strpos(heard_of_crypto, "purchases")
replace heard_of_crypto = "hobby motive" 					if strpos(heard_of_crypto, "hobby")
tab heard_of_crypto


*heard of crypto new dummy
gen heard = (heard_of_crypto == "speculative motive")
label define heard 0 "0. Non-speculative motive" 1 "1. Speculative motive" 
label values heard heard
label variable heard "Speculative motive"


*generate type_objective dummy variable
gen type_objective=0 if typeobjective=="consumer"
replace type_objective=1 if typeobjective=="investor"
label define type2label 0 "Consumer" 1 "Investor"
label values type_objective type2label


*generate type dummy variable
gen type=0 if typeselfreport=="Other (please specify)"
replace type=1 if typeselfreport=="Casual investor for a personal portfolio"
replace type=2 if typeselfreport=="Institutional Investor"
replace type=3 if typeselfreport=="Accredited investor"
label define typelabel 0 "Other" ///
1 "Casual investor for a personal portfolio" ///
2 "Institutional investor" 3 "Accredited investor"
label values type typelabel


*Type new dummy
gen typenew = inlist(typeselfreport, "Accredited investor", "Institutional Investor")
label define typenewlabel 0 "0. Type: Amateur" 1 "1. Type: Professional"
label values typenew typenewlabel
label variable typenew "Type: Professional"


*Income dummy: <=100k & >100k
gen incomenewdummy = inlist(income, "> $300,000", "Between $100,000 and $150,000", ///
	"Between $150,000 and $200,000", "Between $200,000 and $300,000")
label define incomenewlabel 0 "0. Income: Poor" 1 "1. Income: Rich"
label values incomenewdummy incomenewlabel
label variable incomenewdummy "Income: Rich"

*Age dummy: <=30 & >30
gen agenewdummy = inlist(age, "46 years - 60 years", "> 60 years", "30 years - 45 years")
label define agenewlabel 0 "0. Age: Young" 1 "1. Age: Old"
label values agenewdummy agenewlabel
label variable agenewdummy "Age: Old"

*Country dummy: North America vs Other
gen countrynewdummy = inlist(country, "Africa", "Asia", " Australia", "Europe", ///
	"South America")
label define countrynewlabel 0 "0. Country: North America" 1 "1. Country: Outside US"
label values countrynewdummy countrynewlabel
label variable countrynewdummy "Country: Outside US"	

*Recode wave: wave 1 == 0, wave 2 == 1
recode wave (1 = 0) (2 = 1), gen(wave2)
label define wave2label 0 "0. Wave 1" 1 "1. Wave 2"
label variable wave2 "Wave 2"
label values wave2 wave2label


*generate first purchase time variable: 2017 vs before 2017
gen first_time = (first_purchase_time == "2017 and later")
label define firstlabel 0 "0. First Purchase: Early" 1 "1. First Purchase: Late"
label values first_time firstlabel
label variable first_time "First Purchase: Late"

*generate (short-term) expectation dummy variable
gen short_increase = (expectationsvalue=="Increase") if expectationsvalue !="I dont know"
gen short_decrease = (expectationsvalue=="Decrease") if expectationsvalue !="I dont know"
label variable short_increase "Price increase"
label variable short_decrease "Price decrease"

*industry acceptance (long-term expectation) new dummy
gen long_decrease = (accept_across_industry == "It will never become mainstream")
label variable long_decrease "Never mainstream"


* proof of work/stake
gen pow = !inlist(currency_id, "ripple", "ALT", "swftcoin")

label variable currencies_potential "Currencies Potential"




*------------------------------------------------------------------------------*
* Main Variables *
*------------------------------------------------------------------------------*
** Drop missing income
drop if missing(income)
* 2,916 observations deleted

** total quantity
gen quantity_new = 0 if quantity == ""
replace quantity_new = 500 if quantity == "< $1,000"
replace quantity_new = 5500 if quantity == "$1,000 - $10,000"
replace quantity_new = 55000 if quantity == "$10,000 - $100,000"
replace quantity_new = 550000 if quantity == "$100,000 - $1,00,0000"
replace quantity_new = 1000000 if quantity == "> $1,00,0000"

** crypto weights: weighted
bysort currency_id: egen invested_subjects 		= total(choice)	//# subjects invest in such currency
by currency_id: gen percent_currency 			= invested_subjects/_N	//% subjects invest in such currency
bysort household_id: egen weight_denominator 	= total(choice * percent_currency)
gen weight_quantity 	= percent_currency * choice / weight_denominator	//individual weight on each currency
replace weight_quantity = 0 if weight_denominator == 0

** crypto weights: equally weighted
bysort household_id: egen weight_denominator_equal = total(choice)
gen weight_quantity_equal = 1/weight_denominator_equal
replace weight_quantity_equal = 0 if choice == 0

** crypto weights: weighted by group
sort incomenewdummy agenewdummy countrynewdummy
egen group_id = group(incomenewdummy agenewdummy countrynewdummy)

bysort group_id: gen subjects_bygroup 							= _N	//# subjects invest in such currency
bysort group_id currency_id: egen invested_subjects_bygroup 	= total(choice)	//# subjects invest in such currency
by group_id currency_id: gen percent_currency_bygroup 			= invested_subjects_bygroup/subjects_bygroup	//% subjects invest in such currency
bysort household_id: egen weight_denominator_bygroup			= total(choice * percent_currency_bygroup)
gen weight_quantity_bygroup 	= percent_currency_bygroup * choice / weight_denominator_bygroup	//individual weight on each currency
replace weight_quantity_bygroup = 0 if weight_denominator_bygroup == 0


** quantity
gen quantity_crypto_weighted 			= quantity_new * weight_quantity
gen quantity_crypto_weighted_equal 		= quantity_new * weight_quantity_equal
gen quantity_crypto_weighted_bygroup 	= quantity_new * weight_quantity_bygroup


** income
gen income_new = 50000 if income == "< $100,000"
replace income_new = 125000 if income == "Between $100,000 and $150,000"
replace income_new = 175000 if income == "Between $150,000 and $200,000"
replace income_new = 250000 if income == "Between $200,000 and $300,000"
replace income_new = 300000 if income == "> $300,000"





*------------------------------------------------------------------------------*
* Treat swftcoin and bytecoin-bcn as ALT *
*------------------------------------------------------------------------------*
replace currency_id = "bitcoin_cash" if currency_id == "bitcoin-cash"
replace currency_id = "bytecoin_bcn" if currency_id == "bytecoin-bcn"

preserve

keep if inlist(currency_id, "swftcoin", "bytecoin_bcn")
collapse (max) choice, by(household_id)
rename choice alt_choice
tempfile alt_choice
save `alt_choice', replace

restore

merge m:1 household_id using `alt_choice', nogen
replace choice = 1 if (currency_id == "ALT") & (alt_choice == 1)

drop alt_choice

drop if currency_id == "swftcoin"
* 5,499 obs remove
drop if currency_id == "bytecoin_bcn"
* 5,499 obs remove





*------------------------------------------------------------------------------*
* Dependent Variables *
*------------------------------------------------------------------------------*
gen wealth = income_new * 6.6

* modify illegitimate weights
replace wealth = quantity_new if wealth < quantity_new & quantity_new !=.

bysort household_id: gen cash = wealth - quantity_new	//cash = wealth - quantity
*gen w_crypto_weighted = quantity_crypto_weighted / wealth	// currency weight = currency quantity / wealth
gen w_cash = cash / wealth	// cash weight = cash / wealth

*gen dep = w_crypto_weighted/w_cash
foreach type in  weighted weighted_equal weighted_bygroup { 
	gen w_crypto_`type' = quantity_crypto_`type' / wealth	// currency weight = currency quantity / wealth
	gen dep_`type' = w_crypto_`type'/w_cash
}



*---
gen wealth_robust0 = income_new * 3
* modify illegitimate weights
replace wealth_robust0 = quantity_new if wealth_robust0 < quantity_new & quantity_new !=.

bysort household_id: gen cash_robust0 = wealth_robust0 - quantity_new	//cash = wealth - quantity
*gen w_crypto_weighted = quantity_crypto_weighted / wealth	// currency weight = currency quantity / wealth
gen w_cash_robust0 = cash_robust0 / wealth_robust0	// cash weight = cash / wealth

*gen dep = w_crypto_weighted/w_cash
	gen w_crypto_weighted_robust0 = quantity_crypto_weighted / wealth_robust0	// currency weight = currency quantity / wealth
	gen dep_weighted_robust0 = w_crypto_weighted_robust0/w_cash_robust0

	
	
*---
gen wealth_robust1 = income_new * 4
* modify illegitimate weights
replace wealth_robust1 = quantity_new if wealth_robust1 < quantity_new & quantity_new !=.

bysort household_id: gen cash_robust1 = wealth_robust1 - quantity_new	//cash = wealth - quantity
*gen w_crypto_weighted = quantity_crypto_weighted / wealth	// currency weight = currency quantity / wealth
gen w_cash_robust1 = cash_robust1 / wealth_robust1	// cash weight = cash / wealth

*gen dep = w_crypto_weighted/w_cash
	gen w_crypto_weighted_robust1 = quantity_crypto_weighted / wealth_robust1	// currency weight = currency quantity / wealth
	gen dep_weighted_robust1 = w_crypto_weighted_robust1/w_cash_robust1


*---
gen wealth_robust2 = income_new * 5
* modify illegitimate weights
replace wealth_robust2 = quantity_new if wealth_robust2 < quantity_new & quantity_new !=.

bysort household_id: gen cash_robust2 = wealth_robust2 - quantity_new	//cash = wealth - quantity
*gen w_crypto_weighted = quantity_crypto_weighted / wealth	// currency weight = currency quantity / wealth
gen w_cash_robust2 = cash_robust2 / wealth_robust2	// cash weight = cash / wealth

*gen dep = w_crypto_weighted/w_cash
	gen w_crypto_weighted_robust2 = quantity_crypto_weighted / wealth_robust2	// currency weight = currency quantity / wealth
	gen dep_weighted_robust2 = w_crypto_weighted_robust2/w_cash_robust2

*---
gen wealth_robust3 = income_new * 7
* modify illegitimate weights
replace wealth_robust3 = quantity_new if wealth_robust3 < quantity_new & quantity_new !=.

bysort household_id: gen cash_robust3 = wealth_robust3 - quantity_new	//cash = wealth - quantity
*gen w_crypto_weighted = quantity_crypto_weighted / wealth	// currency weight = currency quantity / wealth
gen w_cash_robust3 = cash_robust3 / wealth_robust3	// cash weight = cash / wealth

*gen dep = w_crypto_weighted/w_cash
	gen w_crypto_weighted_robust3 = quantity_crypto_weighted / wealth_robust3	// currency weight = currency quantity / wealth
	gen dep_weighted_robust3 = w_crypto_weighted_robust3/w_cash_robust3


*------------------------------------------------------------------------------*
* Remove missing obs *
*------------------------------------------------------------------------------*
drop if missing(short_increase) 
* 4,590 obs remove; 


drop if  missing(dep_weighted)
* 162 obs remove; 41,823 remains

*------------------------------------------------------------------------------*
* Save data_sharepost *
*------------------------------------------------------------------------------*


save "data/working/data_platform.dta", replace 



